import axios from './myAxios';

// 请求所有的分类信息
export const reqAllClasses = () => axios.get('/classes?method=findAll')

// 管理员登录
export const reqLogin = ({ username, password }) => axios(`/users?method=login&username=${username}&password=${password}`)

// 请求所有的商品信息
export const reqAllProducts = () => axios(`/products?method=findAll`);

// 添加商品分类
export const reqAddClasses = ({ name }) => axios(`/classes?method=add&name=${name}`)

// 更新商品分类
export const reqUpdateClasses = ({ name, id }) => axios(`/classes?method=update&name=${name}&id=${id}`)

// 删除商品分类
export const reqDeleteClasses = (id) => axios(`/classes?method=delete&id=${id}`)

// 添加商品信息post请求
export const reqAddProduct = (product) => axios.post('/users', product);

// 更新商品信息post请求
export const reqUpdateProduct = (product) => axios.post('/products', product);

// 删除商品信息
export const reqDeleteProduct = (id) => axios(`/products?method=delete&id=${id}`)

// 请求仪表盘信息
export const reqHomeInfo = () => axios(`/homes`)

// 条件查询商品信息
export const reqQueryData = ({ classesId, minPrice, maxPrice }) => {
    let query = '/products?method=queryData'
    if (classesId) {
        query += `&classesId=${classesId}`;
    }
    if (minPrice) {
        query += `&minPrice=${minPrice}`;
    }
    if (maxPrice) {
        query += `&maxPrice=${maxPrice}`;
    }
    return axios(query);
};